package com.ljf.interestingmaps.streetview;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.TextView;


import com.ljf.interestingmaps.R;

import java.util.ArrayList;
import java.util.List;

public class StreetViewAdapter extends BaseAdapter{

   List<StreetViewBean>datas =new ArrayList<>();
   Context context;

    private int cardWidth;
    private int cardHeight;

    public StreetViewAdapter(List<StreetViewBean>_datas, Context _context)
    {
        this.datas=_datas;
         this.context=_context;
        DisplayMetrics dm = _context.getResources().getDisplayMetrics();
        float density = dm.density;
        cardWidth = (int) (dm.widthPixels - (2 * 18 * density));
        cardHeight = (int) (dm.heightPixels - (338 * density));

    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public StreetViewBean getItem(int position) {
        if(datas==null ||datas.size()==0) return null;
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        StreetViewBean  streetviewdata = getItem(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_new_item, parent, false);
            holder = new ViewHolder();
            convertView.setTag(holder);
            convertView.getLayoutParams().width = cardWidth;
            holder.portraitView = (ImageView) convertView.findViewById(R.id.portrait);
            holder.portraitView.getLayoutParams().height = cardHeight;
            holder.nameView = (TextView) convertView.findViewById(R.id.name);;
            holder.collectView.setTag("关注");
            holder.collectView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//
//        Glide.with(parent.getContext()).load(talent.headerIcon)
//                .centerCrop().placeholder(R.drawable.default_card)
//                .into(holder.portraitView);
//        holder.nameView.setText(String.format("%s", talent.nickname));

//        final CharSequence no = "暂无";
//
//        holder.cityView.setHint(no);
//        holder.cityView.setText(talent.cityName);
//        holder.cityView.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.home01_icon_location,0,0);
//
//        holder.eduView.setHint(no);
//        holder.eduView.setText(talent.educationName);
//        holder.eduView.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.home01_icon_edu,0,0);
//
//        holder.workView.setHint(no);
//        holder.workView.setText(talent.workYearName);
//        holder.workView.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.home01_icon_work_year,0,0);


        return convertView;
    }



    private static class ViewHolder {
        ImageView portraitView;
        TextView nameView;
        TextView cityView;
        TextView eduView;
        TextView workView;
        CheckedTextView collectView;
    }

}
